package com.jvm.栈内存溢出;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.List;

public class 栈内存溢出3 {
    public static void main(String[] args) throws JsonProcessingException {
        Student stu = new Student("张三",29);
        Dept dept = new Dept("研发组");

        List list = new ArrayList<Student>();
        list.add(stu);

        //互相赋值
        stu.setDept(dept);
        dept.setList(list);

        /*
            底层在调用get方法
         */
        String jsonStr = new ObjectMapper().writeValueAsString(stu);
        System.out.println(jsonStr);
        //可以通过@JsonIgnore来忽略冲突的字段
    }
}
